<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title>商品详情页</title>
	<link rel="stylesheet" type="text/css" href="css/global.css" />
	<link rel="stylesheet" type="text/css" href="css/header.css" />
	<link rel="stylesheet" type="text/css" href="css/footer.css" />
	<link rel="stylesheet" type="text/css" href="css/details.css" />
	<link rel="stylesheet" type="text/css" href="font-awesome-4.7.0/css/font-awesome.css" />
</head>

<body>
	<div id="header"></div>
	<div class="main">
		<div class="container">
			<!-- 第一行：商品的摘要信息 -->
			<div class="major mb20">
				<!-- 左侧的图片区 -->
				<section class="imgarea">
					<ul class="thumbnails">
						<li><img src="img/thumbnail01.png"></li>
						<li><img src="img/thumbnail02.png"></li>
					</ul>
					<div class="bigimg">
						<img src="img/goods-big.png">
					</div>
				</section>
				<!-- 右侧的文本区 -->
				<section>
					<h2 id="title">Smartisan T恤 任天堂发售“红白机”</h2>
					<p id="sell_point">100%中国棉、舒适拉绒质地</p>
					<hr>
					<p id="price" class="price">￥299</p>
					<hr>
					<div class="number-bar">
						<span>数量</span>
						<span class="number-control">-</span>
						<span>1</span>
						<span class="number-control">+</span>
					</div>
					<hr>
					<button class="btn-blue">加入购物车</button>
				</section>
			</div>
			<!-- 第二行： 商品详细信息 -->
			<div class="information module">
				<h3 class="title">产品信息</h3>
				<div id="description">
					<img class="goods-info" src="img/goods-info.jpg">
				</div>
			</div>
		</div>
	</div>
	<div id="footer"></div>
	<script type="text/javascript" src="js/jquery.js"></script>
	<script type="text/javascript">
		$('#header').load('component/header.html')
		$('#footer').load('component/footer.html')
	</script>
	<script src="js/url.utils.js"></script>
	<script>
		$(document).ready(function () {
			$.ajax({
				url: "http://localhost:8080/mall/detail",
				type: "GET",
				data: {
					pid: paramFromUrl('pid')
				},
				dataType: "json",
				success: function(result) {
					// 如果查不到商品
					if(result.code != 0) {
						return;
					}
					// 如果查得到商品, 得到商品信息
					var detail = result.data;
					// 显示缩略图
					$(".thumbnails").empty();
					$(detail.thumbnails).each(function (i, element) {
						$(".thumbnails").append(
							$("<li>").append(
								$("<img>").attr("src", element)
							)
						);
					});
					// 显示大图
					$(".bigimg > img").attr("src", detail.cover);
					// 显示标题, 卖点, 价格
					$("#title").text(detail.title); 
					$("#sell_point").text(detail.sellPoint);
					$("#price").text(detail.price);
					// 显示详细描述
					$("#description").html(detail.description);
				}
			});
		});
	</script>
</body>

</html>